﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Vehicle.Web.Pages.Task
{
    /// <summary>
    /// Copyright (C) M-Tear团队
    /// 文 件 名：Cargo_Task.aspx.cs
    /// 版    本：v1.00.0000
    /// 创建标识：2009-09-02   Created by 杨光远 V1.00.0000
    /// 功能说明：任务分配页面类
    /// 注意事项：无
    /// 
    /// 更新记录：
    /// 
    /// </summary>
    public partial class Cargo_Task : Component.PageBase
    {
        #region---基本实例化---
        BLL.Task b_Task = new Vehicle.BLL.Task();
        BLL.Log b_Log = new Vehicle.BLL.Log();
        Model.ComponentsInfo m_ComponentsInfo = new Vehicle.Model.ComponentsInfo();
        public string url;
        public string onshow;//定义没有数据时页面的显示内容
        #endregion

        #region---基本操作---
        /// <summary>
        /// 页面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Request.QueryString["id"] != null && Request.QueryString["id"] != "")
                {
                   url = Request.QueryString["id"].ToString();
                
                    RepeaterDataBind();//绑定数据
                }
                else
                {
                    Common.MessageHelper.AlertBack("您的操作有误,请重新尝试!");
                }
            }
        }
            /// <summary>
        /// 绑定页面Repeater数据
        /// </summary>
        protected void RepeaterDataBind()
        {
  
            this.Anp_Page.RecordCount = b_Task.GetAllSearchCount(new Model.ComponentsInfo("Task","C_Card", b_Task.GetModel(new Vehicle.Model.ComponentsInfo ("Cargo","C_ID",Request.QueryString["id"].ToString(),"1","1","C_IsDelete","1","C_ID")).Rows[0]["C_Card"].ToString(), "1", "1", "T_IsDelete", "1", "T_Time", Vehicle.Common.TextHelper.StringToDateTime((this.Gmdp_Start.DateString)), Vehicle.Common.TextHelper.StringToDateTime((this.Gmdp_End.DateString)), "T_ID"));//根据下拉菜单选择的进行数据绑定获得总数
            m_ComponentsInfo.startIndex = Anp_Page.StartRecordIndex;//当前页的起始索引
            m_ComponentsInfo.endIndex = Anp_Page.EndRecordIndex;//当前页的结束索引 
            m_ComponentsInfo.condition = "C_Card";//条件一
            m_ComponentsInfo.result = b_Task.GetModel(new Vehicle.Model.ComponentsInfo("Cargo", "C_ID", Request.QueryString["id"].ToString(), "1", "1", "C_IsDelete", "1", "C_ID")).Rows[0]["C_Card"].ToString();//匹配结果一
            m_ComponentsInfo.Scondition = "T_IsDelete";//条件三
            m_ComponentsInfo.Sresult = "1";//匹配结果三
            if (Gmdp_Start.DateString != "")//判断起始时间是否为空
            {
                m_ComponentsInfo.StartTime = Vehicle.Common.TextHelper.StringToDateTime(this.Gmdp_Start.DateString);
            }
            if (Gmdp_End.DateString != "")//判断结束时间是否为空
            {
                m_ComponentsInfo.EndTime = Vehicle.Common.TextHelper.StringToDateTime(Gmdp_Start.DateString);
            }
            b_Task.RepeaterBind(ReptShow, m_ComponentsInfo);//绑定Repeater控件
            if (ReptShow.Items.Count == 0)//判断没有数据时页面的显示内容
            {
                onshow = "当前页面无数据";
            }
            else
            {
                onshow = "";
            }
        }
        /// <summary>
        /// 数据分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
           
            RepeaterDataBind();

        }
      
        /// <summary>
        /// 根据时间选择数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Select_Click(object sender, EventArgs e)
        {
            RepeaterDataBind();
        }

        /// <summary>
        /// Rept绑定数据事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                ((LinkButton)(e.Item.FindControl("lbtn_Delete"))).Attributes.Add("onClick", "return   confirm('您确定删除该任务？');");

                Label lab_M_ID = (Label)e.Item.FindControl("lab_M_ID");//更改所属车队为中文显示
                try
                {
                    lab_M_ID.Text = b_Task.GetModel(new Model.ComponentsInfo("Motorcade", "M_ID", lab_M_ID.Text, "M_ID")).Rows[0]["M_Name"].ToString();//绑定车队名称
                }
                catch
                {
                    lab_M_ID.Text = "无";
                }

                Label lab_P_ID = (Label)e.Item.FindControl("lab_P_ID");//更改所属驾驶员为中文显示
                try
                {
                    lab_P_ID.Text = b_Task.GetModel(new Model.ComponentsInfo("Pilot", "P_ID", lab_P_ID.Text, "P_ID")).Rows[0]["P_Name"].ToString();//绑定驾驶员姓名
                }
                catch
                {
                    lab_P_ID.Text = "无";
                }
                Label lab_V_ID = (Label)e.Item.FindControl("lab_V_ID");//更改车辆为中文显示
                try
                {
                    lab_V_ID.Text = b_Task.GetModel(new Model.ComponentsInfo("Vehicles", "V_ID", lab_V_ID.Text, "V_ID")).Rows[0]["V_LicenseNum"].ToString();//绑定车牌号码
                }
                catch
                {
                    lab_V_ID.Text = "无";
                }
                Label lab_T_Type = (Label)e.Item.FindControl("lab_T_Type");//更改接收情况
                switch (lab_T_Type.Text)
                {
                    case "0": lab_T_Type.Text = "已取消"; break;
                    case "1": lab_T_Type.Text = "执行中"; break;
                    case "2": lab_T_Type.Text = "已完成"; break;

                }
            }

        }
        /// <summary>
        /// Rept激发事件
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ReptShow_ItemCommand(object source, RepeaterCommandEventArgs e)
        {

            DataTable dt = b_Task.GetModel(new Vehicle.Model.ComponentsInfo("Task", "T_ID", e.CommandArgument.ToString(), "T_ID"));
            if (dt.Rows[0]["T_Type"].ToString() != "1")//判断当前类型
            {
                if (e.CommandName == "Delete")
                {

                    b_Task.AllUpdate(new Model.ComponentsInfo("Task", "T_IsDelete", "1", "T_ID", dt.Rows[0]["T_ID"].ToString()));//更新任务表
                    b_Log.Add(new Vehicle.Model.LogInfo(session_ID, DateTime.Now, "成删除功任务编号为" +e.CommandArgument.ToString()  + "的任务信息"));//添加日志
                    ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('删除成功！')", true);
                    RepeaterDataBind();
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(UPanel, this.GetType(), "click", "alert('当前任务正在执行中,不能删除,您可以通过编辑状态后再删除!')", true);
            }
        }
        #endregion 
    }
}